import { Body, Controller, Get, HttpCode, HttpStatus, Post, Request, UseGuards } from '@nestjs/common';
import { AuthService } from './auth.service';
import { AuthLoginDto } from './dto/auth-login.dto';
import { ApiBearerAuth, ApiHeader, ApiOperation, ApiTags } from '@nestjs/swagger';
import { AuthGuard } from '@nestjs/passport';

@ApiBearerAuth() // 需要token
// @Roles(RoleEnum.admin)
@ApiTags('Auth')
@Controller({
	path: 'auth',
	version: '1',
})
export class AuthController {
	constructor(private readonly authService: AuthService) {}

	@Post('/login')
	@HttpCode(HttpStatus.OK)
	login(@Body() AuthLoginProfileDto: AuthLoginDto) {
		return this.authService.login(AuthLoginProfileDto);
	}

	@ApiBearerAuth() // 需要token
	@UseGuards(AuthGuard('jwt'))
	@ApiOperation({
		tags: ['查询当前登录的用户权限'],
		description: '查询当前登录的用户权限',
	})
	@ApiHeader({
		name: 'authoriation',
		required: true,
		description: 'token',
	})
	@Get('/getUserAllPermissionList')
	getUserAllPermissionList(@Request() request) {
		const { roleId } = request.user;
		return this.authService.getUserAllPermissionList(roleId);
	}

	@ApiBearerAuth() // 需要token
	@UseGuards(AuthGuard('jwt'))
	@ApiOperation({
		tags: ['查询当前登录的用户权限'],
		description: '查询当前登录的用户权限',
	})
	@ApiHeader({
		name: 'authoriation',
		required: true,
		description: 'token',
	})
	@Get('/getUserAllMenuList')
	getUserAllMenuList(@Request() request) {
		const { roleId } = request.user;
		return this.authService.getUserAllMenuList(roleId);
	}
}
